<?php
// $Id: functions.php,v 1.2 2005/03/18 12:52:24 onokazu Exp $
//  ------------------------------------------------------------------------ //
//                XOOPS - PHP Content Management System                      //
//                    Copyright (c) 2000 XOOPS.org                           //
//                       <http://www.xoops.org/>                             //
//  ------------------------------------------------------------------------ //
//  This program is free software; you can redistribute it and/or modify     //
//  it under the terms of the GNU General Public License as published by     //
//  the Free Software Foundation; either version 2 of the License, or        //
//  (at your option) any later version.                                      //
//                                                                           //
//  You may not change or alter any portion of this comment or credits       //
//  of supporting developers from this source code or any supporting         //
//  source code which is considered copyrighted (c) material of the          //
//  original comment or credit authors.                                      //
//                                                                           //
//  This program is distributed in the hope that it will be useful,          //
//  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
//  GNU General Public License for more details.                             //
//                                                                           //
//  You should have received a copy of the GNU General Public License        //
//  along with this program; if not, write to the Free Software              //
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
//  ------------------------------------------------------------------------ //

function newsOpenTable()
{
    echo "<table width='100%' border='0' cellspacing='1' cellpadding='8' style='border: 2px solid #2F5376;'><tr class='bg4'><td valign='top'>\n";
}

function newsCloseTable()
{
    echo '</td></tr></table>';
}

function newsthemecenterposts($title, $content)
{
    echo '<table cellpadding="4" cellspacing="1" width="98%" class="outer"><tr><td class="head">'.$title.'</td></tr><tr><td><br />'.$content.'<br /></td></tr></table>';
}


//wanikoo
function newsGetStyleURL($aFile){
	global $news_theme;
	$StyleURL = XOOPSNEWSINCURL."/".$news_theme."/".$aFile;

	if ( file_exists(XOOPSNEWSINCPATH."/".$news_theme."/".$aFile)){
		return $StyleURL;
	}else{
		return XOOPSNEWSINCURL."/".$aFile;
	}
}
//
function newsGetIconURL($aFile){
	global $news_theme;
	$IconURL = XOOPSNEWSIMGURL."/".$news_theme."/".$aFile;

	if ( file_exists(XOOPSNEWSIMGPATH."/".$news_theme."/".$aFile)){
		return $IconURL;
	}else{
		return XOOPSNEWSIMGURL."/".$aFile;
	}
}

//
function news_letters()
{
/*
    global $xoopsModule;

    $letterchoice = "<div>" . _MD_BROWSETOTOPIC . "</div>";
    $letterchoice .= "[  ";
    $alphabet = array ("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z");
    $num = count($alphabet) - 1;
    $counter = 0;
    while (list(, $ltr) = each($alphabet))
    {
        $letterchoice .= "<a href='" .XOOPSNEWSURL. "/index.php?list=$ltr'>$ltr</a>";
        if ($counter == round($num / 2))
            $letterchoice .= " ]<br />[ ";
        elseif ($counter != $num)
            $letterchoice .= "&nbsp;|&nbsp;";
        $counter++;
    }
    $letterchoice .= " ]";
    return $letterchoice;
*/
}


function news_toolbar()
{
    global $xoopsModuleConfig, $xoopsUser;
    $submissions = 0;
    if (is_object($xoopsUser))
    {
    $submissions = 1;
    }
    elseif (!is_object($xoopsUser) && $xoopsModuleConfig['anonpost'])
    {
    $submissions = 1;
    }
	
    $toolbar = "[ <a href='index.php'>"._MI_NEWS_NAME."</a> | ";
    if ($submissions == 1)
    {
        $toolbar .= "<a href='submit.php'>" . _MI_NEWS_SMNAME1 . "</a> | ";
    }
    $toolbar .= "<a href='archive.php'>" . _MI_NEWS_SMNAME2 . "</a> ]";
    return $toolbar;
}

function news_html2text($document)
{
	// PHP Manual:: function preg_replace
	// $document should contain an HTML document.
	// This will remove HTML tags, javascript sections
	// and white space. It will also convert some
	// common HTML entities to their text equivalent.

	$search = array ("'<script[^>]*?>.*?</script>'si",  // Strip out javascript
	                 "'<[\/\!]*?[^<>]*?>'si",          // Strip out HTML tags
	                 "'([\r\n])[\s]+'",                // Strip out white space
	                 "'&(quot|#34);'i",                // Replace HTML entities
	                 "'&(amp|#38);'i",
	                 "'&(lt|#60);'i",
	                 "'&(gt|#62);'i",
	                 "'&(nbsp|#160);'i",
	                 "'&(iexcl|#161);'i",
	                 "'&(cent|#162);'i",
	                 "'&(pound|#163);'i",
	                 "'&(copy|#169);'i",
	                 "'&#(\d+);'e");                    // evaluate as php

	$replace = array ("",
	                 "",
	                 "\\1",
	                 "\"",
	                 "&",
	                 "<",
	                 ">",
	                 " ",
	                 chr(161),
	                 chr(162),
	                 chr(163),
	                 chr(169),
	                 "chr(\\1)");

	$text = preg_replace($search, $replace, $document);
	return $text;
}

?>